package com.dongdongshop.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.em.ConstantEnum;
import com.dongdongshop.pojo.StatusCode;
import com.dongdongshop.pojo.TbSeller;
import com.dongdongshop.service.SellerService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("sellerController")
public class SellerController {
    @Reference
    private SellerService sellerService;
    //跳转商家管理
    @RequestMapping("toseller")
    public String toSeller(String name,String nickName,Model model){
        //查询所有
        List<TbSeller> list = sellerService.findAll(name,nickName);
        model.addAttribute("list",list);
        return "admin/seller";
    }

    //查询当前商家对象
    @RequestMapping("selectById")
    @ResponseBody
    public StatusCode selectById(String sellerId){
        if (sellerId == null){
            return StatusCode.build(ConstantEnum.NULL_ERROR);
        }
        TbSeller tbSeller = sellerService.selectById(sellerId);
        if (tbSeller == null){
            return StatusCode.build(ConstantEnum.ERROR);
        }
        return StatusCode.build(ConstantEnum.SUCCESS).setT(tbSeller);
    }

    //修改商家状态
    @RequestMapping("updateStatus")
    @ResponseBody
    public StatusCode updateStatus(TbSeller tabSeller){
        if (tabSeller == null){
            return StatusCode.build(ConstantEnum.NULL_ERROR);
        }
        Boolean b = sellerService.updateStatus(tabSeller);
        if (!b){
            return StatusCode.build(ConstantEnum.UPDATE_ERROR);
        }
        return StatusCode.build(ConstantEnum.UPDATE_SUCCESS);
    }

}
